package com.forenow.demo.demo21;

public class UserManager {
    String[] name=new String[2];
    String[] pass=new String[2];
    public void register(String username,String password) throws CustomException{
        //查询字符串长度
        int nameLength=username.length();
        int passwordLength=password.length();
        //检验用户名和密码是否为空
        if (username.equals("")||password.equals("")) {
            throw new CustomException("用户名和密码不能为空!");
    }
        //判断用户名nameLength的长度
        if (nameLength<6||nameLength>14) {
            throw new CustomException("长度不符合规范");
        }
        //判断用户名passwordLength的长度
        if (passwordLength<6||passwordLength>14) {
            throw new CustomException("长度不符合规范");
        }
        for (int i = 0; i <name.length ; i++) {
            if (name[i]==null&&pass[i]==null) {
                name[i]=username;
                pass[i]=password;
                System.out.println("注册成功");
                return;
            }
        }
        throw new CustomException("用户已经无法注册了");
    }
    public String[] returnName(){
        return name;
    }
    public String[] returnPass(){
        return pass;
    }
}
